package com.zyit.dao;

import com.zyit.DataObject.T_goods;
import com.zyit.util.BeanRowMapper;
import com.zyit.util.DBHelp;


import java.util.List;

public class T_goodsDaoSYY {
    private DBHelp dbHelp = new DBHelp();

    public int InsertGoods(String goods_name, String price, String stock, String c1, String c2, String c3, String goods_desc,String file) {
        String sql = "INSERT INTO t_goods (goods_name,price,stock,classify_level1_id,classify_level2_id,classify_level3_id,goods_desc,file_name) VALUES (?,?,?,?,?,?,?,?)";
        return dbHelp.executeUpdate(sql, goods_name, price, stock, c1, c2, c3, goods_desc,file);

    }

    public int UpdataGoods(String goods_name, String price, String stock, String c1, String c2, String c3, String goods_desc,String file) {
        String sql = "UPDATE t_goods SET  price = ?, stock = ?,  goods_desc = ? ,file_name = ? WHERE classify_level1_id = ? AND classify_level2_id = ? AND classify_level3_id = ? AND goods_name = ?";
        return dbHelp.executeUpdate(sql, price, stock, goods_desc,file, c1, c2, c3, goods_name);

    }




    public List<T_goods> SelectGoods() throws Exception {
        String sql = "select * from t_goods";
        return dbHelp.executeQueryForList(sql, new BeanRowMapper<>(T_goods.class));
    }

    public T_goods SelectIdGoods(String id) throws Exception {
        String sql = "select * from t_goods where id = ?";
        return dbHelp.executeQueryForObject(sql, new BeanRowMapper<>(T_goods.class),id);
    }

    public int DeleteGoods(String id) throws Exception {
        String sql = "DELETE FROM t_goods WHERE id = ? ";
        return dbHelp.executeUpdate(sql, id);
    }
}
